package xyz.wanwanwan.www.hrm.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import xyz.wanwanwan.www.hrm.constant.CoursePromotionState;
import xyz.wanwanwan.www.hrm.domain.Course;
import xyz.wanwanwan.www.hrm.domain.CourseDetail;
import xyz.wanwanwan.www.hrm.domain.CourseMarket;
import xyz.wanwanwan.www.hrm.domain.CoursePromotion;
import xyz.wanwanwan.www.hrm.dto.CoursePromotionDto;
import xyz.wanwanwan.www.hrm.feign.client.CacheFeign;
import xyz.wanwanwan.www.hrm.feign.client.CourseDetailClient;
import xyz.wanwanwan.www.hrm.feign.client.CourseMarketClient;
import xyz.wanwanwan.www.hrm.mapper.CoursePromotionMapper;
import xyz.wanwanwan.www.hrm.service.ICoursePromotionService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Mr.Fu
 * @since 2020-09-18
 */
@Service
public class CoursePromotionServiceImpl extends ServiceImpl<CoursePromotionMapper, CoursePromotion> implements ICoursePromotionService {
    @Autowired
    private CoursePromotionMapper coursePromotionMapper;
    @Autowired
    private CacheFeign cacheFeign;
    @Autowired
    private CourseDetailClient courseDetailClient;
    @Autowired
    private CourseMarketClient courseMarketClient;
    @Override
    public void quickSaleCourse(CoursePromotionDto dto) {
        CoursePromotion coursePromotion = dto.getCoursePromotion();
        Course course = dto.getCourse();
        //课程id
        coursePromotion.setCourseId(course.getId());
        //课程名
        coursePromotion.setName(course.getName());
        //原价
        coursePromotion.setOldPrice(dto.getCourseMarket().getPrice());
        //课程封面
        coursePromotion.setPic(course.getPic());
        //促销状态：1正在促销 2促销结束
        coursePromotion.setState(CoursePromotionState.COURSE_PROMOTION_STATUS_LOADING);
        //详情
        coursePromotion.setDescription(courseDetailClient.get(course.getId()).getDescription());
        //原售价
        coursePromotion.setOldPrice(courseMarketClient.get(course.getId()).getPrice());
        coursePromotionMapper.insert(coursePromotion);
        cacheFeign.savePromotion(coursePromotion);
    }

}
